//
//  HomeViewController.m
//  DataTransfer
//
//  Created by 宋润理 on 2023/12/15.
//  Copyright © 2023 iCocos. All rights reserved.
//

#import "HomeViewController.h"
#import "SWDataPkgViewController.h"
#import "ReciveFileViewController.h"
#import "AssetHelper.h"


@interface HomeViewController () 


@end

@implementation HomeViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self fetchAllData];
    self.title = @"数据传输";
    [self setLeftItemWithIcon:[UIImage imageNamed:@"back"] title:nil selector:@selector(onClickBack)];

    UIButton *recieveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [recieveBtn setTitle:@"新手机接收数据" forState:UIControlStateNormal];
    recieveBtn.backgroundColor = MainThemeColor;
    recieveBtn.layer.cornerRadius = 10;
    recieveBtn.clipsToBounds = YES;
    [recieveBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    [recieveBtn addTarget:self action:@selector(onClickRecieve) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:recieveBtn];
    [recieveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(@(-100));
        make.right.equalTo(@(-25));
        make.left.equalTo(@(25));
        make.height.equalTo(@(50));
    }];
    
    UIButton *sendBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [sendBtn setTitle:@"旧手机发送数据" forState:UIControlStateNormal];
    sendBtn.backgroundColor = MainThemeColor;
    sendBtn.layer.cornerRadius = 10;
    sendBtn.clipsToBounds = YES;
    [sendBtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    [sendBtn addTarget:self action:@selector(onClickSend) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:sendBtn];
    [sendBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.equalTo(recieveBtn);
        make.bottom.equalTo(recieveBtn.mas_top).offset(-25);
    }];
    
    UIImageView *mainImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"main.jpeg"]];
    mainImage.contentMode = UIViewContentModeScaleAspectFit;
    [self.view addSubview:mainImage];
    [mainImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(@(25));
        make.right.equalTo(@(-25));
        make.bottom.equalTo(sendBtn.mas_top).offset(-25);
    }];
        
}
- (void)onClickBack {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)fetchAllData {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [ASSETHELPER removeAllTmpData];
        [ASSETHELPER fetchAllPhotosAndVideos];
        [ASSETHELPER fetchAllContacts];
    });
}

- (void)onClickSend {
    SWDataPkgViewController * vc = [[SWDataPkgViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}


- (void)onClickRecieve {
    ReciveFileViewController *vc = [[ReciveFileViewController alloc] initWithFileCallback:^(NSString *filePath) {
        
    }];
    [self.navigationController pushViewController:vc animated:YES];
}



@end
